package thirdwork.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import thirdwork.dao.UserDao;
import thirdwork.dao.impl.UserImpl;
import thirdwork.domain.User;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		resp.setCharacterEncoding("UTF-8");
		UserDao userdao = new UserImpl();
		User user = userdao.findByName(req.getParameter("uname"));
		if (req.getParameter("pwd").equals(user.getPassword())) {
			resp.sendRedirect(req.getContextPath() + "/ShowEmployee");
		} else {
			System.out.println("666");
			System.out.println(req.getParameter("uname") + user.getPassword());
		}
	}
}
